import HTMLParser
import urllib
import re


urlString = "http://www.sitelix.sk/sitel-popnetix/sitelix-u%C5%BE%C3%ADvatelia"
urlText = []
pathOut = "ixp_members.txt"


class Parse146 (HTMLParser.HTMLParser):
    
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "p":
            self.check = True
    
    def handle_data (self, data):
        if self.check == True:
            m = re.match("^AS(\d+) $",data)
            if m:
                data = m.group(1)
                if data not in urlText:
                    urlText.append(data)
            self.check = False


lparser = Parse146()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "146 %s" % item
fileOut.close()